/**
 * ReportGear(2011)
 */
package com.reportgear.designer.pane.headerfooter.editor;

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;

import net.abbp.report.model.headerfooter.GroupPageNumHFElement;
import net.abbp.report.model.headerfooter.HFElement;

import com.reportgear.core.swing.pane.base.JBasePane;
import com.reportgear.designer.pane.style.ReportFontPane;
import com.reportgear.report.model.headerfooter.editor.ElementEditor;

/**
 * 面板-页眉页脚-页码元素编辑
 * 
 * @version 1.0 2011-4-22
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class GroupPageNumElementEditor extends JBasePane implements ElementEditor {
	/**
	 * UID
	 */
	private static final long serialVersionUID = 1609730377387601578L;
	private GroupPageNumHFElement element;
	private JTabbedPane tabbedPane;
	private ReportFontPane fontStylePane;

	public GroupPageNumElementEditor() {
		this.initComponents();
	}

	private void initComponents() {
		this.setLayout(new BorderLayout());

		this.tabbedPane = new JTabbedPane();
		this.add(this.tabbedPane, BorderLayout.CENTER);

		this.fontStylePane = new ReportFontPane();

		this.tabbedPane.addTab("字体", this.fontStylePane);
	}

	@Override
	public void populate(HFElement element) {
		this.element = (GroupPageNumHFElement) element;

		this.fontStylePane.populate(this.element.getFontStyle());
	}

	@Override
	public HFElement update() {
		if (this.element == null) {
			return null;
		}

		this.element.setFontStyle(this.fontStylePane.update());

		return this.element;
	}

	@Override
	public int showInDialog(Component c) {
		String caption = "页码";
		if (this.element != null) {
			caption = this.element.getCaption();
		}

		return this.showDialog(SwingUtilities.getWindowAncestor(c), caption, 400, 360);
	}
}